﻿using System;
using System.Collections.Generic;
using Windows.UI.ApplicationSettings;

namespace MVAScratchPad.Services
{
    public class SettingsService
    {
        private readonly SettingsPane _settingsPane;

        /// <summary>
        ///     Initializes a new instance of the <see cref="T:System.Object" /> class.
        /// </summary>
        public SettingsService()
        {
            _settingsPane = SettingsPane.GetForCurrentView();
            _settingsPane.CommandsRequested += SettingsPaneOnCommandsRequested;
        }

        public Action<IList<SettingsCommand>> GetCommandsAction { get; set; }

        private void SettingsPaneOnCommandsRequested(SettingsPane sender, SettingsPaneCommandsRequestedEventArgs args)
        {
            if (GetCommandsAction != null)
            {
                GetCommandsAction(args.Request.ApplicationCommands);
            }
        }

        public void Cleanup()
        {
            _settingsPane.CommandsRequested -= SettingsPaneOnCommandsRequested;
        }
    }
}